package com.jichangxiu.common.entity.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jichangxiu.common.constant.Constants;
import com.jichangxiu.common.entity.bo.Record;

import java.io.Serializable;
import java.util.List;

public class PageResult extends Record implements Serializable {

    private static final long serialVersionUID = 1L;

    private PageResult() {
    }

    public static PageResult build(Page<?> page) {
        return build(page.getTotal(), page.getRecords());
    }

    public static PageResult build(Page<?> page, List<?> data) {
        return build(page.getTotal(), data);
    }

    public static PageResult build(Long total, List<?> data) {
        PageResult pageResult = new PageResult();
        pageResult.set(Constants.TO_CLIENT_PAGE_TOTAL_KEY, total);
        pageResult.set(Constants.TO_CLIENT_PAGE_DATA_KEY, data);
        return pageResult;
    }

    public long getTotal() {
        return this.getLong(Constants.TO_CLIENT_PAGE_TOTAL_KEY);
    }

    public List<?> getList() {
        return this.getList(Constants.TO_CLIENT_PAGE_DATA_KEY);
    }

    public <T> List<T> getList(Class<T> cs) {
        return this.getList(Constants.TO_CLIENT_PAGE_DATA_KEY, cs);
    }

}
